<?php

use Hanson\Vbot\Message\Text;

require_once __DIR__ . '/../inc/Wechat.php';
/***************************/

class Warning extends Wechat{
    private $_yhh;
    private $_mumbo;
    private $_warning;
    const YHH = 'y.h.h';
    const MUMBO = 'Mumbo';
    const WARNING = 'WARNING';

    function __construct()
    {
        parent::__construct();
    }


    function dealMsg($message)
    {
        parent::dealMsg($message);
        if($this->isYhh()){$this->fwMumbo();}
        elseif($this->isFWWarning()){$this->fwWarning();}
        elseif($this->isFWYhh()){$this->fwYhh();}
    }

    protected function isYhh()
    {
        if($this->message['from']['UserName']==$this->_yhh){
            return true;
        }else{
            return false;
        }
    }

    protected function isFWWarning()
    {
        if($this->message['from']['UserName']==$this->_mumbo
        and substr($this->message['content'],0,4)=='fww '){
            return true;
        }else{
            return false;
        }
    }

    protected function isFWYhh()
    {
        if($this->message['from']['UserName']==$this->_mumbo
            and substr($this->message['content'],0,4)=='fwy '){
            return true;
        }else{
            return false;
        }
    }

    protected function fwMumbo()
    {
        $word = 'from y.h.h:(回复指令fwy [内容])
';
        $word.=$this->message['content'];
        Text::send($this->_mumbo,$word);
    }

    protected function fwWarning()
    {
        $word = substr($this->message['content'],4);
        Text::send($this->_warning,$word);
    }

    protected function fwYhh()
    {
        $word = substr($this->message['content'],4);
        Text::send($this->_yhh,$word);
    }



    /*************初始化**************/
    function initConfig()
    {
        $groupsVbot = vbot('groups');
        $friendVbot = vbot('friends');
        $this->_warning = $groupsVbot->getUsernameByNickname(self::WARNING, true);
        $this->_yhh = $friendVbot->getUsernameByNickname(self::YHH,true);
        $this->_mumbo = $friendVbot->getUsernameByNickname(self::MUMBO,false);
        var_dump( $this->_warning,$this->_yhh, $this->_mumbo);
    }



}




$a = new Warning();
$a->vbot->server->serve();